<?php
// 助手函数

// 模板调用
if (!function_exists('view')) {
function view($template=''){
    global $app,$controller,$action;
    $template= $template==''? $controller.'/'.$action.'.php' : $template;
    return _APP_PATH_ . '/' . _ADDONS_NAME_ . '/'.$app.'/view/'.$template;
}
}

// url网址跳转
if (!function_exists('url')) {
function url($url=[],$vars = ''){
    global $app,$controller,$action;

    $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ?"https://": "http://";

    if(isset($url[3])){
		$dirname= str_replace('\\','/',dirname($_SERVER['PHP_SELF']) );
		$dirname = $dirname=='/'?'':$dirname;
        $phpself = $dirname . '/' . $url[3] ;
    }else{
        $phpself = $_SERVER['PHP_SELF'];
    }
	

    //$url = '?app='.$url[0].'&c='.$url[1].'&a='.$url[2];
    $url = '?s='.$url[0].'/'.$url[1].'/'.$url[2];
    if(!empty($vars)){
        // 解析参数
        if (is_array($vars)) {
            // aaa=1&bbb=2 转换成数组
            //parse_str($vars, $vars);
            $vars = http_build_query($vars);
        }
        $vars = '&' . $vars;
    }
    
    return $protocol . $_SERVER['HTTP_HOST'] . $phpself . $url . $vars;
}
}


// 表名函数
if (!function_exists('tablename')) {
    function tablename($name){
        return  $GLOBALS["config"]['database']['prefix'] . $name;
    }
}


//跳转（message）
if (!function_exists('message')) {
    function message($message,$url){
        echo "<script> alert('".$message."'); </script>";
        echo "<meta http-equiv='Refresh' content='0;URL=".$url."'>";
        exit();
    }
}
